local url = { }

-- 字符串转为16进制编码
function url.encode(str)
    local hexStr = ""
    for i = 1, #str do
        local byte = string.byte(str, i)
        local hex = string.format("%02X", byte)
        hexStr = hexStr .. hex
    end
    return hexStr
end

-- 16进制编码转为字符串
function url.decode(hexStr)
    local str = ""
    for i = 1, #hexStr, 2 do
        local hex = string.sub(hexStr, i, i + 1)
        local byte = tonumber(hex, 16)
        local char = string.char(byte)
        str = str .. char
    end
    return str
end

return url 